import http from "@/utils/http";
import type { User, UserForm, UserListParams, PageResponse } from "@/types/user";

interface ResponseEntity<T> {
  code: number;
  message: string;
  data: T;
}

export const userManageApi = {
  /**
   * 获取用户列表
   */
  getUserList: (params: UserListParams): Promise<ResponseEntity<PageResponse<User>>> => {
    return http.post("/api/user/list/page/vo", params);
  },

  /**
   * 添加用户
   */
  addUser: (data: UserForm): Promise<ResponseEntity<User>> => {
    return http.post("/api/admin/user/add", data);
  },

  /**
   * 更新用户
   */
  updateUser: (userId: number, data: UserForm): Promise<ResponseEntity<User>> => {
    return http.put(`/api/admin/user/update/${userId}`, data);
  },

  /**
   * 删除用户
   */
  deleteUser: (userId: number): Promise<ResponseEntity<boolean>> => {
    return http.delete(`/api/admin/user/delete/${userId}`);
  },

  /**
   * 获取用户详情
   */
  getUserDetail: (userId: number): Promise<ResponseEntity<User>> => {
    return http.get(`/api/admin/user/detail/${userId}`);
  }
};